package services

import (
	"github.com/labstack/gommon/log"
	"law_case_api/models"
)

type LawService struct {
}

// GetLawByName 根据用户名查询律师信息，主要用于登录验证
func (law LawService) GetLawByName(username string) (models.WzjLawInfo, error) {
	var wzjLawInfo models.WzjLawInfo
	sql := "SELECT id,enterprise_id,law_account,law_name,law_pwd,is_admin,law_role FROM wzj_db.wzj_law_info WHERE law_account = ?;"
	if err := db.Raw(sql, username).Find(&wzjLawInfo).Error; err != nil {
		log.Error("GetLawByName -- 根据用户名查询律师信息失败，失败原因：", err)
		return wzjLawInfo, err
	}
	return wzjLawInfo, nil
}

// GetLawByCondition 根据用户名查询律师信息，主要用于登录验证
func (law LawService) GetLawByCondition(_law models.WzjLawInfo) (models.WzjLawInfo, error) {
	var wzjLawInfo models.WzjLawInfo
	sql := "SELECT id,enterprise_id,law_account,law_name,law_pwd,is_admin,law_role FROM wzj_db.wzj_law_info WHERE id = ?;"
	if err := db.Raw(sql, _law.Id).Find(&wzjLawInfo).Error; err != nil {
		log.Error("GetLawByCondition -- 根据用户名查询律师信息失败，失败原因：", err)
		return wzjLawInfo, err
	}
	return wzjLawInfo, nil
}
